<template>
<div class="addNew">
  <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="毕设名称">
    <el-input v-model="form.bisheName"></el-input>
  </el-form-item>
  <el-form-item label="所属院校">
    <el-select v-model="form.univercity" placeholder="请选择所属院校">
      <el-option v-for="(item,index) in Object.keys(selectList)" :key="index" :label="item" :value="item"></el-option>
      
    </el-select>
  </el-form-item>
  <el-form-item label="所属专业" aria-disabled="false">
    <el-select v-model="form.major" placeholder="请选择所属专业">
      <el-option v-for="(item,index) in selectList[form.univercity]" :key="index" :label="item" :value="item"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="主要内容">
    <el-input type="textarea" v-model="form.content"></el-input>
  </el-form-item>
  <el-form-item label="老师献言">
    <el-input type="textarea" v-model="form.teachersays"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    
  </el-form-item>
</el-form>
</div>
</template>

<script>
import axios from 'axios'
export default {
        data(){
            return {
                form: {
                    bisheName: '',
                    major: '',
                    univercity: '',
                    content: '',
                    teachersays: '',
                    teacherName:'',
                    teacherId:'',
                    islock:null
                },
                selectList:{
                  '信息工程学院':['计算机科学与技术','软件工程','人工智能'],
                  '商学院':['营销学','人力资源管理','经济学','金融工程','工商管理'],
                  '体育学院':['体育教育','运动训练','民族传统体育','武术与民族传统']
                }
              }
            },
        methods: {
            onSubmit() {
                //向新建毕设接口传递数据
                axios.post(`/prod-api/bishe`,this.form)
                        .then(response=>{
                            this.$message({
                                message: response.data.msg,
                                type: 'success'
                            });
                        })

                console.log(this.form);

                Object.keys(this.form).forEach(element =>{
                    if(element !== 'islock' && element != 'teacherName' && element != 'teacherId'){
                      this.form[element] = ''
                    }
                })
            }
    },
    created(){
        this.form.teacherName = localStorage.getItem('teacherName')
        this.form.teacherId = localStorage.getItem('teacherId')
        console.log(this.form);
      }
}
</script>

<style>
.addNew{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
</style>